<template>
	<view class="page-fade-in" :style="{opacity: pageOpc}">
		<template v-if="pageOpc">
			<view class="content">
				<view class="point-box">温馨提示：每个订单仅可选用一个优惠卡券！</view>
				<view class="empty-box flexWarpCenterColumn" v-if="couponList.length==0">
					<image src="../../static/coupon/empty.png" class="empty-image"></image>
					<view class="empty-tips">这里空空如也！</view>
				</view>
				<view class="coupon-box">
					<view class="coupon-item flexWrapNo" v-for="(item,index) in couponList" :key='index' @tap="chooseCoupon(index)">
						<view class="left-circular"></view>
						<view class="coupon-left flexWarpCenterColumn">
							<text class="money">{{item.price}}</text>
							<text class="money-tip">可用余额</text>
						</view>
						<view class="coupon-line"></view>
						<view class="coupon-right flexWrap">
							<view class="flexWarpColumn">
								<text class="coupon-name">{{item.title}}</text>
								<text>面值：{{item.price}}元</text>
								<text>有效期：{{item.start_time}}至{{item.end_time}}</text>
								<!-- <text v-if="item.valid_timedata==1">有效期：永久</text>
								<text v-if="item.valid_timedata==2">有效期：{{item.start}}至{{item.end}}</text>
								<text v-if="item.valid_timedata==3">有效期：{{item.valid_configure}}天</text> -->
							</view>
							<view class="user-btn">使用</view>
						</view>
						<view class="right-circular"></view>
					</view>
				</view>
			</view>
		</template>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageOpc:0,
				couponList:[],
				couponIndex:0,
				order_price:""
			}
		},
		onReady(){
			setTimeout(() => {
				this.pageOpc=1
			}, 100)
		},
		onLoad(ops) {
			this.order_price=ops.order_price
			this.getCouponlist();
		},
		methods: {
			chooseCoupon(index){
				this.couponIndex=index
				let pages = getCurrentPages(); //当前页
				let beforePage = pages[pages.length - 2]; //上个页面
				beforePage.$vm.couponId = this.couponList[index].id
				beforePage.$vm.couponMoney = this.couponList[index].price
				beforePage.$vm.couponTitle = this.couponList[index].title
				uni.navigateBack({
					delta:1
				})
			},
			getCouponlist(){
				this.$request.post(this.$api.orderCoupon, {
					store_id:uni.getStorageSync('store_id'),
					order_price:this.order_price
				}, {
					token:true
				}).then(res => {
					let {
						data = {}
					} = res;
					if (res.code==1) {
						for (let i in data) {
							data[i].start_time=this.$tools.formatDay(data[i].start_time)
							data[i].end_time=this.$tools.formatDay(data[i].end_time)
						}
						this.couponList=data
						console.log(this.couponList)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		padding-bottom: 100upx;
	}
	.content{
		padding: 0 36upx;
	}
	.point-box{
		font-size: 24upx;
		font-family: PingFang SC;
		font-weight: 400;
		line-height: 40upx;
		color: #FFB726;
		margin: 34upx 0;
	}
	.coupon-box{
		.coupon-item{
			height: 200upx;
			background:linear-gradient(116deg, #C2FF60 0%, #68A973 100%);
			border-radius: 10upx;
			position: relative;
			margin-bottom: 20upx;
			.left-circular{
				width: 30upx;
				height: 30upx;
				border-radius: 50%;
				background: #F7F7F7;
				position: absolute;
				left: -15upx;
			}
			.right-circular{
				width: 30upx;
				height: 30upx;
				border-radius: 50%;
				background: #F7F7F7;
				position: absolute;
				right: -15upx;
			}
			.coupon-left{
				width: 200upx;
				.money{
					font-size:46upx;
					font-family: PingFang SC;
					font-weight: 600;
					line-height: 100upx;
					color: #000000;
				}
				.money-tip{
					font-size: 24upx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #000000;
				}
			}
			.coupon-line{
				width: 2upx;
				height: 140upx;
				background: #96CE61;
			}
			.coupon-right{
				font-size: 22upx;
				font-family: PingFang SC;
				font-weight: 400;
				line-height: 44upx;
				color: #000000;
				margin-left: 22upx;
				flex:1;
				// padding-right: 32upx;
				.coupon-name{
					font-size: 30upx;
					font-family: PingFang SC;
					font-weight: 600;
					line-height: 50upx;
					color: #000000;
				}
				.user-btn{
					width: 88upx;
					height: 60upx;
					line-height: 60upx;
					text-align: center;
					background:#FFB726;
					border-radius: 16upx;
					font-size: 28upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #333;
					position: absolute;
					right: 20rpx;
				}
			}
		}
	}
	.empty-box{
		margin-bottom: 64upx;
		.empty-image{
			width: 400upx;
			height: 400upx;
		}
		.empty-tips{
			font-size: 24upx;
			font-family: PingFang SC;
			font-weight: 400;
			line-height: 34upx;
			color: #FFFFFF;
		}
	}
</style>
